#include <math.h>
#include <Probability.h>

Probability::Probability(double probability)
{
    if(probability < 0)
        probability = 0;
    if(probability > 1)
        probability = 1;
    probability_m = probability;
}

bool Probability::operator==(const Probability& probability) const
{
    return fabs(probability_m - probability.probability_m) < PROBABILITY_PRECISION ? true : false;
}

bool Probability::operator!=(const Probability& probability) const
{
    return fabs(probability_m - probability.probability_m) < PROBABILITY_PRECISION ? false : true;
}

Probability Probability::operator~() const
{
    return Probability(1 - probability_m);
}

Probability Probability::operator&(const Probability& probability) const
{
    return Probability(probability_m * probability.probability_m);
}

Probability Probability::operator|(const Probability& probability) const
{
    return Probability(1 - (1 - probability_m) * (1 - probability.probability_m));
}
